package com.originit.product.service.impl

import com.originit.product.ProductApplicationTests
import com.originit.product.dto.CartDTO
import com.originit.product.service.ProductService
import org.junit.jupiter.api.Test

import org.junit.jupiter.api.Assertions.*
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
import org.springframework.test.annotation.Rollback
import javax.transaction.Transactional

@Component
@Transactional
internal class ProductServiceImplTest: ProductApplicationTests() {

    @Autowired
    lateinit var service: ProductService

    @Test
    fun findUpAll() {
        assertTrue(service.findUpAll().size > 0)
    }

    @Test
    fun findByOrderIds() {
        assertNotNull(service.findForOrderByIds(arrayListOf("157875196366160022")))
    }

    @Test
    @Rollback
    fun minusStockByIds() {
        println(service.findForOrderByIds(arrayListOf("157875196366160022"))[0].productStock)
        service.minusStockByIds(arrayListOf(CartDTO(productId = "157875196366160022",productQuantity = 1)))
        println(service.findForOrderByIds(arrayListOf("157875196366160022"))[0].productStock)
    }
}